﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StudentManagement.Utils;

namespace StudentManagement.UCs
{
    public partial class FeatureControl : UserControl
    {
        public FeatureControl()
        {
            InitializeComponent();
        }

        // Event Handler 
        public event EventHandler NewStudentEvent;
        private void InvokieNewStudent()
        {
            var handler = NewStudentEvent;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
        public event EventHandler<FileEventArgs> LoadFileEvent;
        private void InvokieLoadFile(FileEventArgs e)
        {
            var handler = LoadFileEvent;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<FileEventArgs> SaveFileEvent;
        private void InvokieSaveFile(FileEventArgs e)
        {
            var handler = SaveFileEvent;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        public event EventHandler ExitEvent;
        private void InvokieExit()
        {
            var handler = ExitEvent;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }

        private void btnNewStudent_Click(object sender, EventArgs e)
        {
            InvokieNewStudent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            InvokieExit();
        }

        private void btnSaveFile_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "txt files (*.txt)|*.txt";
            saveFile.FilterIndex = 2;
            saveFile.RestoreDirectory = true;

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                InvokieSaveFile(new FileEventArgs(saveFile.FileName));   
            }
        }

        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFile.FilterIndex = 2;
            openFile.RestoreDirectory = true;

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                InvokieLoadFile(new FileEventArgs(openFile.FileName));
            }
        }
    }
}
